package com.masterclient.app.modules.alipush;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.alibaba.sdk.android.push.AndroidPopupActivity;
import com.masterclient.app.MainActivity;
import com.masterclient.app.R;
import com.masterclient.app.utils.CommonUtil;
import com.eoner.baselib.utils.activity.UtilActivity;

import java.util.Map;

/**
 * 辅助推送通道指定打开的弹窗activity,目前包括:小米弹窗、华为弹窗
 */
public class PushPopupActivity extends AndroidPopupActivity {
    final String TAG = "===PushPopup";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_push_popup);
    }

    /**
     * 弹窗消息打开互调。辅助弹窗通知被点击时,此回调会被调用,用户可以从该回调中获取相关参数进行下一步处理
     * @param title
     * @param content
     * @param extraMap
     */
    @Override
    protected void onSysNoticeOpened(String title, String content, Map<String, String> extraMap) {
        Log.d(TAG, "Receive ThirdPush notification, title: " + title + ", content: " + content + ", extraMap: " + extraMap);
        finish();
        if (UtilActivity.isCurActivity("MainActivity")) {
            CommonUtil.goAnyWhere(this,  (extraMap!=null && extraMap.get("target") != null) ?extraMap.get("target"):"", CommonUtil.targetIdMultiFormat(extraMap), "", "", "");
        }else {
            Intent intent = new Intent(PushPopupActivity.this, MainActivity.class);
            intent.putExtra("target", extraMap.get("target"));
            intent.putExtra("target_id", CommonUtil.targetIdMultiFormat(extraMap));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent, null);
        }
    }
}
